(require "yaml-syck")
(use-package :yaml-syck)

(defun dump-report (target count dt)
  (let ((fmt "
xyzzy/syck:
  result:
    ~A:
      wallclock: ~D
      base: 1000
      loaded: ~D
  benchmark_script: xyzzy-syck.l
  language: lisp
  interpreter:
    name: xyzzy
    version: ~A
  library:
    name: yaml-syck
    native_library:
      name: syck
      version: 0.61+svn231+patches
    language: [xyzzy lisp, C]
    version: ~A
"))
    (format t fmt
            target
            dt
            count
            (software-version)
            (syck-xyzzy-binding-version))))

(defun yaml-bench (n target outfile)
  (with-output-to-temp-buffer ("*tmp*")
    (let ((s (get-internal-real-time))
          (count 0))
      (handler-case
          (progn
            (dotimes (i n)
              (syck-load-documents
               target
               :from :filename
               :callback #'(lambda (y) (incf count))))
            (let ((e (get-internal-real-time)))
              (dump-report target count (- e s))))
        (error (c)
          (format t "~S" c)))
      (write-file outfile))))
